package com.smartleanx.module.hrm.service.dingDing;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smartleanx.module.hrm.dal.dataobject.dingDing.DingFalseDiligence;
import com.smartleanx.module.hrm.dal.dataobject.dingDing.SystemFalseDiligence;
import com.smartleanx.module.hrm.dal.mysql.dingDing.DingFalseDiligenceMapper;
import com.smartleanx.module.hrm.dal.mysql.dingDing.SystemFalseDiligenceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mybatis-plus
 * @since 2025-02-12
 */
@Service
public class SystemFalseDiligenceServiceImpl implements SystemFalseDiligenceService {

    @Autowired
    private SystemFalseDiligenceMapper systemFalseDiligenceMapper;

    @Override
    public PageInfo<SystemFalseDiligence> selectPage(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<SystemFalseDiligence> dingFalseDiligences =
                systemFalseDiligenceMapper.selectList(new LambdaQueryWrapper<SystemFalseDiligence>() {{
                    like(!ObjectUtils.isEmpty(name), SystemFalseDiligence::getLeaveName, name);
                }});
        return new PageInfo<>(dingFalseDiligences);
    }

    @Override
    public List<SystemFalseDiligence> selectList(String userId) {
        List<SystemFalseDiligence> dingFalseDiligences = systemFalseDiligenceMapper.selectList(null);
        dingFalseDiligences.forEach(dingFalseDiligence -> {
            dingFalseDiligence.setTime(1);
        });
        return dingFalseDiligences;
    }

    @Override
    public SystemFalseDiligence getById(String userId, Integer id) {
        SystemFalseDiligence dingFalseDiligence = systemFalseDiligenceMapper.selectById(id);
        dingFalseDiligence.setTime(1);
        return dingFalseDiligence;
    }

    @Override
    public void update(SystemFalseDiligence dingFalseDiligence) {
        systemFalseDiligenceMapper.updateById(dingFalseDiligence);
    }

    @Override
    public void save(SystemFalseDiligence dingFalseDiligence) {
        systemFalseDiligenceMapper.insert(dingFalseDiligence);
    }

    @Override
    public void remove(Integer id) {
        systemFalseDiligenceMapper.deleteById(id);
    }

    @Override
    public SystemFalseDiligence selectByInfo(Integer id) {
        SystemFalseDiligence dingFalseDiligence = systemFalseDiligenceMapper.selectById(id);


        return dingFalseDiligence;
    }
}
